package student;

import java.sql.SQLException;

import basic.ClientConsole;

import com.sun.rowset.CachedRowSetImpl;
import gui.studentScreen;
import flexibility.userData;

public class fillComboBox {
	private userData DBData = new userData();
	private CachedRowSetImpl crs;
	private CachedRowSetImpl rs;
	private static ClientConsole studentConnection;
	private Integer myID;
	
	public fillComboBox(ClientConsole conn, Integer id) {
		studentConnection=conn;
		myID=id;
		rs=getAllMySemesters();
		
		try {
			while (rs.next())
			{ 
				studentScreen.comboBox.addItem(rs.getString(2)+"_"+rs.getString(1));
				System.out.println(rs.getString(1));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	/**
	 * This method returns all the semesters when the student studied
	 * @return semesterID, semesterName, Year
	 */
	public CachedRowSetImpl getAllMySemesters(){
		DBData.deleteAll();
		DBData.addData(49);
		DBData.addData(1);
		DBData.addData(myID);
		studentConnection.acceptMsg(DBData);
		crs = studentConnection.getResults();
		
		return crs;
	}
}
